package org.client.otdr;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.client.otdr.executor.AutoSearchExecutor;
import org.client.otdr.executor.ControlExecutor;
import org.client.otdr.executor.FilelistExecutor;
import org.client.otdr.executor.ResolverAccessor;
import org.client.otdr.executor.SavenameExecutor;
import org.client.otdr.executor.SetupExecutor;
import org.client.otdr.executor.UploadDataExecutor;
import org.openems.entity.Key;

import framework.AbstractDomainService.ActiveAccessor;
import framework.Command;
import framework.webclient.RestSocket;
import framework.webclient.SystemProperty;

public class PostDependency implements Command {
	private Map<Key, Executor> executorMap = new HashMap<Key, Executor>();
	
	public PostDependency(RestSocket restSocket, SystemProperty systemProperty, ActiveAccessor accessor, ResolverAccessor resolverAccessor) {		
		OTDRID id = OTDRID.get();
		executorMap.put(id.CONTROL, new ControlExecutor(accessor, restSocket, systemProperty));
		executorMap.put(id.UPLOADALL, new UploadDataExecutor(accessor, restSocket, systemProperty));
		executorMap.put(id.FILELIST, new FilelistExecutor(accessor, restSocket, systemProperty));
		executorMap.put(id.SAVENAME, new SavenameExecutor(accessor, restSocket, systemProperty));
		executorMap.put(id.WAVELENGTH, new SetupExecutor(accessor, restSocket, systemProperty));
		executorMap.put(id.PULSEWIDTH, new SetupExecutor(accessor, restSocket, systemProperty));
		executorMap.put(id.DISTANCERANGE, new SetupExecutor(accessor, restSocket, systemProperty));
		executorMap.put(id.AUTOSEARCH, new AutoSearchExecutor(accessor, restSocket, resolverAccessor));
	}
	
	@Override
	public void execute(List<Key> changedKey, Key key) {
		for (Key k : changedKey) {
			Executor executor = this.executorMap.get(k);
			if (executor != null) {
				executor.execute(key);
			}
		}
	}
}
